package com.wc.算法基础课.A第一讲基础算法.日期问题.回文日期;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/3/10 10:34
 * @description 回文日期
 * 第一题 https://www.acwing.com/problem/content/468/
 * 第二题 https://www.acwing.com/problem/content/2870/
 */
public class Main {
    static int[] m = new int[]{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30};
    static int st, ed;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        st = sc.nextInt();

         /* 第一个
         ed = sc.nextInt();
         int res = 0;
         if (isRun(st)) m[2] = 29;
         else m[2] = 28;
         while (st <= ed) {
         if (isbd(st)) {
         res++;
         }
         st = nextDay(st);
         }
          */
        st = nextDay(st);
        while (true) {
            if (isbd(st)) break;
            else st = nextDay(st);
        }
        System.out.println(st);
        while (true) {
            if (isABABBABA(st)) break;
            else st = nextDay(st);
        }
        System.out.println(st);
    }

    static boolean isABABBABA(int y) {
        char[] cs = (" " + y).toCharArray();
        return cs[1] == cs[3] && cs[3] == cs[6] && cs[6] == cs[8] &&
                cs[2] == cs[4] && cs[4] == cs[5] && cs[5] == cs[7] && cs[1] != cs[2];
    }

    static boolean isbd(int x) {
        int nx = x;
        int cp = 0;
        while (nx > 0) {
            cp = cp * 10 + nx % 10;
            nx /= 10;
        }

        return cp == x;
    }

    static int nextDay(int x) {
        int y = x / 10000;
        int mth = x / 100 % 100;
        int d = x % 100;
        return nextDay(y, mth, d);
    }

    static int nextDay(int y, int mth, int d) {
        if (d < m[mth]) {
            d++;
        } else if (mth < 12) {
            d = 1;
            mth++;
        } else {
            y++;
            mth = 1;
            d = 1;
            if (isRun(y)) m[2] = 29;
            else m[2] = 28;
        }

        return y * 10000 + mth * 100 + d;
    }

    static boolean isRun(int y) {
        return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
    }
}